from selenium import webdriver
import time
from selenium.webdriver.common.by import By

class Browser_Operat():

    def __init__(self):
        self.driver=webdriver.Chrome()
        self.driver.get('https://www.baidu.com')

    #浏览器的大小设置
    def window_size(self):
        for i in range(3):
            time.sleep(2)
            #设置浏览器的窗口大小
            self.driver.set_window_size(450,800)
            time.sleep(2)
            #最大化
            self.driver.maximize_window()
            #最小化
            self.driver.minimize_window()

    def forward_back(self):
        for i in range(3):
            time.sleep(2)
            #前进
            self.driver.forward()
            time.sleep(2)
            #后退
            self.driver.back()
    #刷新浏览器
    def refresh(self):
        time.sleep(2)
        self.driver.refresh()
    #关闭浏览器
    def quit(self):
        self.driver.quit()

    def close(self):
        #定位新闻的搜索框
        news=self.driver.find_element(By.LINK_TEXT,'新闻')
        # 点击新闻
        news.click()
        time.sleep(3)
        # 关闭
        self.driver.close()


if __name__== '__main__':
    bo = Browser_Operat()
    # bo.window_size()
    bo.forward_back()
    # bo.refresh()
    # bo.close()





